package com.ticket.sass.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ticket.sass.admin.dto.input.coupons.code.CouponCodeBatchListInput;
import com.ticket.sass.admin.mapper.CouponCodeBatchMapper;
import com.ticket.sass.admin.service.BaseService;
import com.ticket.sass.common.entity.tenant.CouponCodeBatchEntity;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 优惠券兑换码批次号表 服务实现类
 * </p>
 *
 * @author ywb
 * @since 2024-07-04
 */
@Service
public class CouponCodeBatchServiceImpl extends ServiceImpl<CouponCodeBatchMapper, CouponCodeBatchEntity> implements BaseService<CouponCodeBatchEntity> {

    public IPage<CouponCodeBatchEntity> iPage(Long couponId, CouponCodeBatchListInput input) {
        IPage<CouponCodeBatchEntity> page = new Page<>(input.getPageNum(), input.getPageSize());
        QueryWrapper<CouponCodeBatchEntity> queryWrapper = new QueryWrapper<>();
        
        if (input.getName() != null) {
            queryWrapper.lambda().like(CouponCodeBatchEntity::getName, input.getName());
        }
        if (input.getBatchNum() != null) {
            queryWrapper.lambda().like(CouponCodeBatchEntity::getBatchNum, input.getBatchNum());
        }
        queryWrapper.orderByDesc("id");
        queryWrapper.eq("coupon_id", couponId);
        IPage<CouponCodeBatchEntity> entityPage = this.page(page, queryWrapper);
       
        return entityPage;
    }
}
